#include "householder.h"

Householder::Householder(){
}

Householder::~Householder(){
}

Matrix Householder::calculate(Matrix &matrix, Matrix &x){
	Matrix tridiagonal(matrix);
	int sgn = 1;
	unsigned int row = tridiagonal.getRow();
	for (unsigned int i = 0; i < row - 2; i++){
		Vector a(row);
		for (unsigned int j = i + 1; j < row ; j++){
			a[j] = tridiagonal[j][i];
		}
		if (a[i + 1] > 0.0)
			sgn = -1;
		else
			sgn = 1;
		
		Vector a_(row);
		a_[i + 1] = sgn * a.length();
		Vector e((a - a_).normalize());
		
		Matrix p ( Matrix(row,row, IDENTITY_MATRIX) - ((e.outterProduct(e))*2.0) );
		tridiagonal = p * tridiagonal * p;
		
		x = x * p;
	}
	
	
// 	std::cout << "matriz depois de householder" <<std::endl;
// 	tridiagonal.print2();
	return tridiagonal;
}
